package br.com.lh.urabuilder.helper
{
	import br.com.lh.urabuilder.business.ViewManager;
	import br.com.lh.urabuilder.model.UraModelLocator;
	import br.com.lh.urabuilder.view.ActionComponent;
	
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.sophware.undoredo.control.UndoStackEvent;
	
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	import mx.core.UIComponent;
	
	public class KeyBoardHelper
	{
		private var parentComponent:UIComponent;
		private var componentManager:ViewManager;
		
		
		public function KeyBoardHelper(parentComponent:UIComponent,componentManager:ViewManager)
		{
			this.parentComponent = parentComponent;
			this.componentManager = componentManager;
		}
		
			public function handle(event:KeyboardEvent):void
			{
				var modelLocator:UraModelLocator = UraModelLocator.getInstance();
				//CTRL + Z
				 if (event.ctrlKey &&  event.keyCode == 90){
					CairngormEventDispatcher.getInstance().dispatchEvent(new UndoStackEvent(UndoStackEvent.UNDO));
				}
				//CTRL + Y
				else if (event.ctrlKey && event.keyCode == 89){
					CairngormEventDispatcher.getInstance().dispatchEvent(new UndoStackEvent(UndoStackEvent.REDO));
				}
				if (componentManager.getSelectedComponents().length ==0){
					return;
				}
				var component:ActionComponent = ActionComponent(event.currentTarget);
				if (event.keyCode == Keyboard.ESCAPE){
					modelLocator.viewManager.selectAll(false);
				}
				else if (event.keyCode == Keyboard.F2 || event.keyCode == Keyboard.ENTER){
					modelLocator.propertieHelper.doOpen(component);
					
				}
			}
			
		
			

	}
}